package pingan.com.quarter_hour.z_presenter;

import android.content.Context;

import java.util.Map;

import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.DisposableSubscriber;
import pingan.com.quarter_hour.bean.BannerBean;
import pingan.com.quarter_hour.bean.ZDuanziItem;
import pingan.com.quarter_hour.view.IView;
import pingan.com.quarter_hour.z_model.ZCrossTalkModel;

import static android.os.Build.VERSION_CODES.M;
import static android.view.View.Z;

/**
 * Created by wk on 2018/1/16.
 */

public class CrossTalkPresenter  implements  ZICrossTake{
    private IView iv;
    private DisposableSubscriber<ZDuanziItem> disposableSubscriber;

    public void attachview(IView iv){
        this.iv=iv;
    }

    //获取段子列表信息
    public void getData(Flowable<ZDuanziItem> flowable){
        disposableSubscriber = flowable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableSubscriber<ZDuanziItem>() {
                    @Override
                    public void onNext(ZDuanziItem bannerBean) {
                        iv.success(bannerBean);
                    }

                    @Override
                    public void onError(Throwable t) {
                        iv.Failes(new Exception(t));
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
    private void detachview(){
        if(disposableSubscriber!=null){
            if(disposableSubscriber.isDisposed()){
                disposableSubscriber.dispose();
            }
        }
    }

    @Override
    public void getCrossTake(String url, Map<String, String> map) {
        ZCrossTalkModel zCrossTalkModel = new ZCrossTalkModel(this);
        zCrossTalkModel.getData(url,map);
    }
}
